home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / MOD2TXT.ZIP / CHAP1.TXT next >
Text File  |  1987-03-25  |  6KB  |  191 lines

  1.                      Chapter 1 - What is a computer program?
  2.  
  3.  
  4.              If  you  are a complete novice to computers,  you  will
  5.         find  the information in this chapter useful.   If you  have
  6.         some experience in computer use, and especially programming,
  7.         you can completely ignore this chapter.  It will deal with a
  8.         few  of  the most fundamental topics of computers  and  will
  9.         have nothing to do with the Modula-2 programming language.
  10.  
  11.                         WHAT IS A COMPUTER PROGRAM?
  12.  
  13.              A computer is nothing but a very dumb machine that  has
  14.         the  ability to perform mathematical operations very rapidly
  15.         and very accurately,  but it can do nothing without the  aid
  16.         of  a program written by a human being.   Moreover,  if  the
  17.         human  being  writes  a program that turns  good  data  into
  18.         garbage, the computer will very obediently, and very rapidly
  19.         turn  good  data into garbage.   It is possible to  write  a
  20.         large  program with one small error that will do just  that.
  21.         In some cases the error will be obvious, but if the error is
  22.         subtle,  the  answers may appear to be right,  and the error
  23.         will go unnoticed.   It is up to you,  the human programmer,
  24.         to write a correct program to tell the computer what to  do.
  25.         You  can  think of the computer as your very obedient  slave
  26.         ready to do your every whim.   It is up to you to tell  your
  27.         slave what you want it to do.
  28.  
  29.              A  computer  program is a "recipe" which  the  computer
  30.         will  use  on  the input data to derive the  desired  output
  31.         data.   It is similar to the recipe for baking a cake.   The
  32.         input data is comparable to the ingredients,  including  the
  33.         heat supplied by the oven.  The program is comparable to the
  34.         recipe instructions to mix,  stir, wait, heat, cool, and all
  35.         other possible operations on the ingredients.  The output of
  36.         the  computer  program  can be compared to  the  final  cake
  37.         sitting  on  the  counter ready to be  cut  and  served.   A
  38.         computer then is composed of two parts,  the data upon which
  39.         the program operates,  and the data.   The data and  program
  40.         are inseparable as implied by the last sentence.
  41.  
  42.                             WHAT ARE CONSTANTS?
  43.  
  44.              Nearly  any computer program requires some numbers that
  45.         never  change throughout the program.   They can be  defined
  46.         once and used as often as needed during the operation of the
  47.         program.   To  return to the recipe analogy,  once you  have
  48.         defined  how  big  a tablespoon is,  you can  use  the  same
  49.         tablespoon without regard to what you are measuring with it.
  50.         When writing a computer program, you can define the value of
  51.         PI  =  3.141592,  and continue to use it wherever  it  makes
  52.         sense knowing that it is available, and correct.
  53.  
  54.  
  55.  
  56.  
  57.                                     Page 5
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.                      Chapter 1 - What is a computer program?
  68.  
  69.  
  70.  
  71.                             WHAT ARE VARIABLES?
  72.  
  73.              In addition to constants,  nearly any computer  program
  74.         uses  some  numbers  that  change in  value  throughout  the
  75.         program.   They can be defined as variables, then changed to
  76.         any  values that make sense to the proper operation  of  the
  77.         program.   An  example  would be the number of eggs  in  the
  78.         above  recipe.   If a single layer of cake required 2  eggs,
  79.         then  a triple layer cake would require 6 eggs.   The number
  80.         of eggs would therefore be a variable.
  81.  
  82.                   HOW DO WE DEFINE CONSTANTS OR VARIABLES?
  83.  
  84.              All  constants and variables have a name and  a  value.
  85.         In  the last example,  the name of the variable was  "eggs",
  86.         and  the value was either 2 or 6 depending on when we looked
  87.         at  the stored value.   In a computer program the  constants
  88.         and variables are given names in much the same manner, after
  89.         which  they  can store any value within the  defined  range.
  90.         Any  computer  language has a means by which  constants  and
  91.         variables can be first named,  then assigned a  value.   The
  92.         means of doing this in Modula-2 will be given throughout the
  93.         remainder of this tutorial.
  94.  
  95.                       WHAT IS SO GOOD ABOUT MODULA-2?
  96.  
  97.              Some  computer languages allow the programmer to define
  98.         constants and variables in a very haphazard manner and  then
  99.         combine data in an even more haphazard manner.  For example,
  100.         if you added the number of eggs, in the above recipe, to the
  101.         number  of  cups  of  flour,  you would arrive  at  a  valid
  102.         mathematical  addition,  but a totally  meaningless  number.
  103.         Some  programming languages would allow you to do just  such
  104.         an addition and obediently print out the meaningless answer.
  105.         Since  Modula-2  requires you to set up your  constants  and
  106.         variables in a very precise manner,  the possibility of such
  107.         a meaningless answer in minimized.   A well written Modula-2
  108.         program has many cross checks to minimize the possibility of
  109.         a completely scrambled and meaningless output.
  110.  
  111.              Notice  however,  in the last statement,  that a  "well
  112.         written" Modula-2 program was under discussion.  It is still
  113.         up  to the programmer to define the data structure in such a
  114.         way that the program can prevent garbage generation.  In the
  115.         end,  the  program will be no better than the analysis  that
  116.         went into the program design.
  117.  
  118.              If you are a novice programmer,  do not be  intimidated
  119.         by any of the above statements.  Modula-2 is a well designed
  120.  
  121.  
  122.  
  123.                                     Page 6
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.                      Chapter 1 - What is a computer program?
  134.  
  135.  
  136.         tool  that  has  been  used successfully  by  many  computer
  137.         novices and professionals.  With these few warnings, you are
  138.         ready to begin.
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.                                     Page 7
  190.  
  191.